package view;

import java.util.ArrayList;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;

import controller.UI;

/**
 * @author Igor
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StatisticsTable extends JTable
{
	/* Current statistics table */
	public static StatisticsTable currentStatisticsTable = null;
	
	/* Table headers */
	private final static String columnNames[] = { "Name", "Number" };
	private final static String rowNames[] = { "Denied sessions", "Accepted sessions" };
	
	public StatisticsTable ()
	{
		super(rowNames.length, columnNames.length);

		JScrollPane sc = new JScrollPane();
		add(sc);
		
		for(int i = 0; i < rowNames.length; i++)
		{
			setValueAt(rowNames[i], i, 0);
		}
		
		build();
		
		currentStatisticsTable = this;
	}
	
	public JTableHeader getLoggerTableHeader()
	{
		TableColumn column = null;
		for (int i = 0; i < columnNames.length; i++)
		{
		    column = getColumnModel().getColumn(i);
		    column.setHeaderValue(columnNames[i]);
		}
		
		return getTableHeader();	
	}
	
	/**
	 * Cancel cell editing for user.
	 */
	public boolean isCellEditable(int row, int column) 
	{
		return false;
	}
	
	
	/**
	 * Fill the table.
	 */
	public void build()
	{
		Integer denied = new Integer(UI.getDeniedSessionsNumber(Settings.historyDepth));
		Integer accepted = new Integer(UI.getAcceptedSessionsNumber(Settings.historyDepth));
			
		setValueAt(denied, 0, 1);
		setValueAt(accepted, 1, 1);
	}	
}
